﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class DataBase_ParamEdit : System.Web.UI.Page
{
    Param MyP = new Param();
    ParamType MyPT = new ParamType();

    public string sEditStatus = "1";


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ParamTypeDataBind();

            try
            {
                sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    SqlDataReader MySDR = MyP .ReadParam ("a.id =" + sID);
                    if (MySDR.Read())
                    {
                        ParamType.Text = MySDR["PCode"].ToString().Trim();
                        Code.Text = MySDR["Code"].ToString().Trim();
                        Name.Text = MySDR["Name"].ToString().Trim();
                        CValue.Text = MySDR["CValue"].ToString().Trim();
                        status.Text = MySDR["Status"].ToString().Trim();
                    }
                }
                else
                {
                }
            }
            catch
            {
            }
        }
    }

    public void ParamTypeDataBind()
    {
        ParamType.DataSource = MyPT.GetParamTypes(" status='1' ");
        ParamType.DataBind();
        ParamType.Items.Insert(0, "全部类别");
        ParamType.Items[0].Value = "";
    }

    protected void SaveData_ServerClick(object sender, EventArgs e)
    {
        string sPid = ParamType.SelectedValue.ToString().Trim();
        string sName = Name.Text.ToString().Trim();
        string sCode = Code.Text.ToString().Trim();
        string sCvalue = CValue.Text.ToString().Trim();
        string sstatus = status.SelectedValue.ToString().Trim();

        string sPersID = (string)Session["Baimasoft_Pers_ID"];
        string sOrgID = (string)Session["Baimasoft_Dept_ID"];


        sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();

        if (sEditStatus == "1")
        {
            int iback = MyP.InsertParam(sPid, sCode, sName, sCvalue, sstatus, sPersID, sOrgID);
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');window.close();</script>");
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
                return;
            }
        }
        else
        {
            int iback = MyP.UpdateParam(sPid, sCode, sName, sCvalue, sstatus, sPersID, sOrgID, this.Request.QueryString["ID"].ToString().Trim());
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.close();</script>");  //window.opener.location.reload();
                return;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                return;
            }
        }
    }
}

